//package com.lt.test.consumer.controller;
//
//import com.alibaba.dubbo.config.annotation.Reference;
//import com.lt.test.api.CgtCustService;
//import com.lt.test.common.exception.CustomException;
//import com.lt.test.common.util.ExcelUtil;
//import com.lt.test.common.util.HttpClientUtil;
//import com.lt.test.entity.DTO.*;
//import com.lt.test.entity.QueryModel.MapQueryModel;
//import net.sf.json.JSONObject;
//import org.apache.poi.hssf.usermodel.HSSFWorkbook;
//import org.apache.shiro.SecurityUtils;
//import org.apache.shiro.subject.Subject;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.OutputStream;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
///**
// * 云超市相关 -- 烟草客户
// *
// * @author zhengchuan
// */
//
//@Controller
//@RequestMapping("/sys/clouderp")
//public class CgtCustController {
//    private static final Logger logger = LoggerFactory.getLogger(ClouderpController.class);
//    @Reference(version = "1.0.0")
//    private CgtCustService cgtCustService;
//
//    /**
//     * 分页查询烟草客户信息
//     *
//     * @param request
//     * @param response
//     * @return
//     */
//    @RequestMapping("/getCgtCustInfo")
//    public
//    @ResponseBody
//    PageDTO<CgtCustDTO> getCgtCustInfo(HttpServletRequest request, HttpServletResponse response) {
//        Integer page = Integer.valueOf(request.getParameter("page"));
//        Integer pageSize = Integer.valueOf(request.getParameter("rows"));
//        String sortedKey = request.getParameter("sidx");
//        String sortedValue = request.getParameter("sord");
//        String filters = request.getParameter("filters");
//        PageDTO<CgtCustDTO> result = null;
//        Map<String, String> params = new HashMap<>(6);
//
//        Subject subject = SecurityUtils.getSubject();
//        ActiveUser activeUser = (ActiveUser) subject.getPrincipal();
//        params.put("userQuYu", activeUser.getChannelName());
//        params.put("userChannelName", activeUser.getRealChannelName());
//        params.put("userEmpName", activeUser.getEmpName());
//        params.put("userQuXianName", activeUser.getQuXianName());
//
//        try {
//            result = cgtCustService.findCgtCustByPage(page, pageSize, sortedKey, sortedValue, filters, params);
//        } catch (CustomException e) {
//            logger.error("获取烟草客户信息失败");
//            e.printStackTrace();
//            result = new PageDTO<>();
//        }
//        return result;
//    }
//
//    /**
//     * 导出Excel
//     *
//     * @param request
//     * @param response
//     * @return
//     */
//    @RequestMapping("/cgtCustInfoExportExcel")
//    public void cgtCustInfoExportExcel(HttpServletRequest request, HttpServletResponse response) throws Exception {
//        String filters = request.getParameter("filters");
//
//        Map<String, Object> map = new HashMap<>(1,1.0F);
//        map.put("sheetName", "烟草客户信息");
//
//        Map<String, String> params = new HashMap<>(6);
//        Subject subject = SecurityUtils.getSubject();
//        ActiveUser activeUser = (ActiveUser) subject.getPrincipal();
//        params.put("userQuYu", activeUser.getChannelName());
//        params.put("userChannelName", activeUser.getRealChannelName());
//        params.put("userEmpName", activeUser.getEmpName());
//
//
//        String[] Keys = new String[]{"SLSMAN_NAME","CUST_NAME","CUST_ADDR","CUST_CODE","BANK_CAR_COUNT","COUNT_ORDER","FIRST_BIND_CAR_TIME","FIRST_PAY_ORDER_TIME","FIRST_LOGIN_TIME"};//,"IS_EXP"
//        String[] columnNames = new String[]{"客户经理","客户名称","客户地址","专卖证号","绑卡张数","订单次数","第一次绑卡时间","第一次支付时间","注册时间"};//,"试点用户"
//        List<Map<String,Object>> result = new ArrayList<>();
//        Integer page = 1;
//        Integer pageSize = 6000;
//        params.put("pageSize",pageSize.toString());
//        while (true) {
//            params.put("page",page.toString());
//            List<Map<String,Object>> data = cgtCustService.cgtCustInfoExportExcel(filters, params);
//            result.addAll(data);
//            if (data == null || data.size() < pageSize) {
//                break;
//            }
//            page++;
//        }
//
//        result.add(0,map);
//        logger.info("开始执行ExcelUtil.createHSSFWorkbook方法");
//        HSSFWorkbook wb = ExcelUtil.createHSSFWorkbook(result, Keys, columnNames);
//        logger.info("执行ExcelUtil.createHSSFWorkbook方法完毕");
//        OutputStream out = response.getOutputStream();
//        response.reset();
//        response.setHeader("Content-Disposition", "attachment;filename="+ new String(("烟草客户信息" + ".xls").getBytes(), "iso-8859-1"));
//        response.setContentType("application/msexcel;charset=UTF-8");
//        logger.info("设置响应信息完成");
//        //输出excel文件
//        wb.write(out);
//        out.close();
//        logger.info("结束生成excel表格");
//    }
//
//    /**
//     * 获取烟草客户信息子表
//     *
//     * @param request  请求参数
//     * @param response 响应
//     * @return
//     */
//    @RequestMapping("/getSubCgtCustInfo")
//    public
//    @ResponseBody
//    PageDTO<DCust2MemberDTO> getSubCgtCustInfo(HttpServletRequest request, HttpServletResponse response) {
////		Integer page = Integer.valueOf(request.getParameter("page"));
////		Integer pageSize = Integer.valueOf(request.getParameter("rows"));
////		String sortedKey = request.getParameter("sidx");
////		String sortedValue = request.getParameter("sord");
////		String filters = request.getParameter("filters");
//        String parentId = request.getParameter("parentId");
//        PageDTO<DCust2MemberDTO> result = null;
//        try {
//            result = cgtCustService.findSubCgtCustByParentId(parentId);
//        } catch (CustomException e) {
//            logger.error("获取烟草客户子表信息失败");
//            e.printStackTrace();
//            result = new PageDTO<>();
//        }
//        return result;
//    }
//
//    /**
//     * 更改用户授权
//     *
//     * @param request
//     * @param response
//     * @return json
//     */
//    @RequestMapping("/accreditCgtCust")
//    public
//    @ResponseBody
//    ResponseDTO accreditCgtCust(HttpServletRequest request, HttpServletResponse response) {
//        ResponseDTO responseDTO = new ResponseDTO();
//        String id = request.getParameter("id");
//        String flag = request.getParameter("flag");
//        try {
//            cgtCustService.accreditCgtCust(id, flag);
//            responseDTO.setCode("200");
//            responseDTO.setSuccess(true);
//            responseDTO.setMessage("更改成功");
//        } catch (CustomException e) {
//            e.printStackTrace();
//            responseDTO.setCode("500");
//            responseDTO.setMessage(e.getMessage());
//        } catch (Exception e) {
//            e.printStackTrace();
//            responseDTO.setCode("500");
//            responseDTO.setMessage("服务器异常");
//        }
//        return responseDTO;
//
//    }
//
//    /**
//     * 发送小云消息
//     *
//     * @param request
//     * @param response
//     * @return
//     */
//    @RequestMapping("/sendCloudingMessage")
//    public
//    @ResponseBody
//    ResponseDTO sendCloudingMessage(HttpServletRequest request, HttpServletResponse response) {
//        ResponseDTO responseDTO = new ResponseDTO();
//        String phone = request.getParameter("phone");
//        String content = request.getParameter("content");
//        try {
//            cgtCustService.sendCloudingMessage(phone, content);
//            responseDTO.setCode("200");
//            responseDTO.setSuccess(true);
//            responseDTO.setMessage("发送成功");
//        } catch (CustomException e) {
//            e.printStackTrace();
//            responseDTO.setCode("500");
//            responseDTO.setMessage(e.getMessage());
//        } catch (Exception e) {
//            e.printStackTrace();
//            responseDTO.setCode("500");
//            responseDTO.setMessage("服务器异常");
//        }
//        return responseDTO;
//    }
//
//    /**
//     * 获取用户相关信息
//     *
//     * @param request
//     * @param response
//     * @return
//     */
//    @RequestMapping("/getUserInfo")
//    public
//    @ResponseBody
//    ResponseDTO getUserInfo(HttpServletRequest request, HttpServletResponse response) {
//        ResponseDTO responseDTO = new ResponseDTO();
//        String custCode = request.getParameter("custCode");
//        try {
//            Map<String, Object> result = cgtCustService.getUserInfo(custCode);
//            System.out.println("================");
//            System.out.println("result: "+result);
//            System.out.println("================");
//            //获取商户信息
//            String URL = "http://10.95.0.233:23912/clouderp-cgt-order-rest/api/cgt/order/getMerchant";
//            Map<String, String> params = new HashMap<>(2, 1.0F);
//            params.put("custCode", custCode);
//            params.put("debugSkipSignValidate", "1");
//            String responseResult = HttpClientUtil.sendPostRequest(URL, params, null, null);
//
//            JSONObject jsonObject = JSONObject.fromObject(responseResult);
//            System.out.println("================");
//            System.out.println("jsonObject: "+jsonObject);
//            System.out.println("================");
//            if ("000".equals(jsonObject.get("code"))) {
//                JSONObject merchant = JSONObject.fromObject(jsonObject.get("data").toString());
//                merchant.remove("remark");
//                result.put("merchant", merchant);
//                URL = "http://10.95.0.233:23912/clouderp-pay-rest/api/pay/getBindedBankCard?";
//                URL = URL + "merId=" + merchant.get("merchantCode").toString() + "&customerId=" + custCode + "&debugSkipSignValidate=1";
//                // URL = "http://10.10.200.240:8094/clouderp-pay-rest/api/pay/getBindedBankCard?merId=105522444589998&customerId=520201100079&debugSkipSignValidate=1";
//                responseResult = HttpClientUtil.sendGetRequest(URL, null);
//                System.out.println("================");
//                System.out.println("responseResult: "+responseResult);
//                System.out.println("================");
//                jsonObject = JSONObject.fromObject(responseResult);
//                System.out.println("================");
//                System.out.println("jsonObject: "+jsonObject);
//                System.out.println("================");
//                if ("000".equals(jsonObject.get("code")) && jsonObject.get("data") != null) {
//                    result.put("bankInfoList", jsonObject.get("data"));
//                }
//            }
//            System.out.println("================");
//            System.out.println(result);
//            System.out.println("================");
//
//            responseDTO.setCode("200");
//            responseDTO.setSuccess(true);
//            responseDTO.setMessage("获取成功");
//            responseDTO.setData(result);
//        } catch (CustomException e) {
//            e.printStackTrace();
//            responseDTO.setCode("500");
//            responseDTO.setMessage(e.getMessage());
//        } catch (Exception e) {
//            e.printStackTrace();
//            responseDTO.setCode("500");
//            responseDTO.setMessage("服务器异常");
//        }
//        System.out.println("================");
//        System.out.println(responseDTO);
//        System.out.println("================");
//        return responseDTO;
//
//    }
//
//    /**
//     * 同步到银联
//     *
//     * @param request
//     * @param response
//     * @return
//     */
//    @RequestMapping("/doSynchronizationUnionpay")
//    public
//    @ResponseBody
//    ResponseDTO doSynchronizationUnionpay(HttpServletRequest request, HttpServletResponse response) {
//        ResponseDTO responseDTO = new ResponseDTO();
//        String custCode = request.getParameter("custCode");
//
//
//        final String URL = "http://10.95.0.233:23912/clouderp-cgt-order-rest/api/cgt/order/syncCustInfo";
//        Map<String, String> params = new HashMap<>(2, 1.0F);
//        params.put("custCode", custCode);
//        params.put("debugSkipSignValidate", "1");
//        try {
//
//
//            String responseResult = HttpClientUtil.sendPostRequest(URL, params, null, null);
//            JSONObject jsonObject = JSONObject.fromObject(responseResult);
//            if (jsonObject.size() == 0 || !"000".equals(jsonObject.get("code"))) {
//                responseDTO.setMessage("同步失败");
//
//            } else {
//
//                responseDTO.setCode("200");
//                responseDTO.setSuccess(true);
//                responseDTO.setMessage("同步成功");
//                responseDTO.setData(jsonObject.get("data"));
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            responseDTO.setCode("500");
//            responseDTO.setMessage("未知错误");
//        }
//        return responseDTO;
//
//    }
//
//
//    /**
//     * 绑卡
//     *
//     * @return
//     */
//    @RequestMapping(value = "/bindBankCard", produces = "application/json; charset=utf-8")
//    public
//    @ResponseBody
//    String bindBankCard(MapQueryModel params) {
////        final String URL = "http://app1:23912/clouderp-pay-rest/api/pay/bindBankCard";
//        final String URL = "http://10.95.0.233:23912/clouderp-pay-rest/api/pay/bindBankCard";
//        String responseResult = HttpClientUtil.sendPostRequest(URL, params.getStringMap(), null, null);
//        logger.info("绑定银行卡，请求参数：" + params.getStringMap() + "结果：" + responseResult);
//        return responseResult;
//    }
//}
